#!/bin/bash
# Text formatting
BLUE='\033[0;34m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color
echo -e "${BLUE}Starting to pull all repositories...${NC}\n"
# Find all .git directories, excluding the .git directory itself if it exists
find . -type d -name ".git" ! -path "./.git" | while read -r gitdir; do
# Get the parent directory of the .git folder (the actual repo directory)
repo_dir=$(dirname "$gitdir")
echo -e "${BLUE}Pulling${NC} ${repo_dir#./}"
cd "$repo_dir" || continue
git pull
cd - > /dev/null
echo ""
done
echo -e "${GREEN}All repositories have been updated!${NC}"Shortcut to Pull GitHub Repos
This is a MacOS tutorial on how to create a shortcut to pull all your local GitHub repositories at once. I have a lot of repositories, and I don’t want to pull them one by one. So I created a shortcut to do this. Here’s how you can do it too.
1 Shell File
The first thing you need is a shell file that pulls all your repositories. Here’s the code:
Save it as pull-all-repos.sh in the root folder of your GitHub repo. I saved it here:
2 Automator App
Secondly, we need an Automator application:
- Open Automator and select “Application” as the type of document.
- In the search bar on the left, type “shell”. You’ll find “Run Shell Script”.
- Double click on “Run Shell Script” from the actions list. It will appear on the workflow area on the right.
- In the shell script box, enter:
cd ~/Documents/GitHub # Change to your GitHub repo dir
./pull-all-repos.sh- Save it as an application. Mine has the name being “Pull All Repos”.
Or you can simply download and unzip this application in my repo.
Thirdly, we need a Quick Action created by Automator:
- Open Automator and select “Quick Action” as the type of document.
- In the search bar on the left, type “launch”. You’ll find “Launch Application”.
- Double click on “Launch Application” from the actions list. It will appear on the workflow area on the right.
- The application will be “Contacts” by default. Change it to the “Pull All Repos” app.
- Save it. Mine has the name being “Pull All Repos”.
You’ll not see the saved directory, but if you wanna access it, it’s here:
/Users/<Your User Folder>/Library/Services
The last step is to set up a keyboard shortcut:
- Open System Settings and scroll down to “Keyboard”.
- Click on “Keyboard Shortcuts…”.
- Select “Services” on the left, and then open the “General” dropdown menu on the right. You’ll see the “Pull All Repos” here.
- Click on the white space on the right and assign your preferred shortcut.
Hints:
If you download my application, the system will block you. You need to go to “Privacy & Security” in “System Settings”, scroll down and grant permission to this app.
The first time you run this, you’ll be prompted:
zsh:2: permission denied: ./pull-all-repos.sh
You need to run these codes in your Terminal:
cd ~/Documents/GitHub # Change to your root dir of GitHub repo
sudo chmod +x pull-all-repos.sh